package com.jubaopen.dao.ibatis;

import java.util.List;
import java.util.Map;

import com.jubaopen.bean.Customer;
import com.jubaopen.dao.CustomerDAO;

public class CustomerDAOImpl extends BaseIBatisDao implements CustomerDAO {

	@Override
	public int add(Customer customer) {
		return (Integer) this.getSqlMapClientTemplate().insert(
				"CustomerMapper.insert", customer);
	}

	@Override
	public int update(Customer customer) {
		return this.getSqlMapClientTemplate().update("CustomerMapper.update",
				customer);
	}

	public Customer getCustomer(Customer customer) {
		return (Customer) this.getSqlMapClientTemplate().queryForObject(
				"CustomerMapper.getCustomer", customer);
	}

	@Override
	public int getCount(Map<String, Object> entity) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject(
				"CustomerMapper.getCount", entity);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Customer> getPagedList(Map<String, Object> entity) {
		return this.getSqlMapClientTemplate().queryForList(
				"CustomerMapper.getPagedList", entity);
	}

	@Override
	public double getConsumeSum(Map<String, Object> entity) {
		double sum =0;
		Object ret = this.getSqlMapClientTemplate().queryForObject(
				"CustomerMapper.getConsumeSum", entity);
		if (ret != null) {
			sum = (Double) ret;
		}
		return sum;
	}

}
